package praktikumid.w10.p1;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;

/**
 * Circle.
 * @author Ago
 *
 */
public class Circle extends Shape {

	/**
	 * Center point of the circle.
	 */
	private Point center;
	/**
	 * Radius.
	 */
	private int radius = 0;
	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		if (center != null) {
			// when drawing, we draw an oval.
			// The left upper point is defined with
			// the (start point - radius) in both axis.
			// The width and the height are 2*radius.
			g.drawOval(center.x - radius, center.y - radius, 
					2 * radius, 2 * radius);
		}
	}

	@Override
	public void drag(MouseEvent e) {
		if (center == null) {
			// if center is not defined (we start dragging),
			// we need to set the center point.
			center = e.getPoint();
		} else {
			// if center already exists (we continue dragging),
			// let's just change the radius.
			radius = (int) center.distance(e.getPoint());
		}
		System.out.println(this);
	}

	@Override
	public void click(MouseEvent e) {
		System.out.println(this);
		if (e.getButton() == MouseEvent.BUTTON3) {
			setColor(Color.RED);
		}
		
	}

	@Override
	public void release(MouseEvent e) {
		if (center != null) {
			isFinished = true;
		}
		
	}

	@Override
	public void move(int dx, int dy) {
		center.setLocation(center.x + dx, center.y + dy);
		
	}

}
